import 'dart:ui';

import 'package:flutter_blog_manage_study/model/language_entity.dart';
import 'package:flutter_blog_manage_study/util/sp/sp_util.dart';
import 'package:get/get.dart';

/// * 作者: Tao
/// * 日期: 2024/3/22
/// * 时间: 14:41
/// * 描述: 语言工具类
class LocalUtil {

  /// 更新语言
  /// * [language] 语言实体
  static void updateLanguage(LanguageEntity language) {
    Locale? local;
    if (language.language == '' || language.country == '') {
      local = Get.deviceLocale;
    } else {
      local = Locale(language.language, language.country);
    }
    if (local != null) {
      Get.updateLocale(local);
    }
  }

  /// 获取当前存储的默认语言
  /// * return [Locale] 语言
  static Locale? getDefaultLanguage() {
    var language = SPUtil.getLanguage();
    if (language == null || language.language == '' || language.country == '') {
      return Get.deviceLocale;
    } else {
      return Locale(language.language, language.country);
    }
  }
}